using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VGSKDZU
    {
        public DataRow Convert2GSKDZU(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryGSKDZU(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["GKMANDANT"] = " ".PadRight(2 ); 
         dwReturn["GKKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["GKART"] = " ".PadRight(20 ); 
         dwReturn["GKVAR"] = " ".PadRight(3 ); 
         dwReturn["GKFARBE"] = " ".PadRight(10 ); 
         dwReturn["GKKDGARNB"] = " ".PadRight(20 ); 
         dwReturn["GKKDFARBB"] = " ".PadRight(20 ); 
         dwReturn["GKAUFMSL"] = " ".PadRight(2 ); 
         dwReturn["GKHUELSE"] = " ".PadRight(6 ); 
         dwReturn["GKSPGEW"] = " ".PadRight(0 ); 
         dwReturn["GKFDRES"] = " ".PadRight(1 ); 
         dwReturn["GKKF"] = " ".PadRight(1 ); 
         dwReturn["GKWICKL"] = " ".PadRight(1 ); 
         dwReturn["GKVPEINH"] = " ".PadRight(4 ); 
         dwReturn["GKBHNR"] = " ".PadRight(1 ); 
         dwReturn["GKNK"] = " ".PadRight(2 ); 
         dwReturn["GKFARBGR"] = " ".PadRight(1 ); 
         dwReturn["GKGRPBEZ"] = " ".PadRight(20 ); 
         dwReturn["GKKDFARBN"] = " ".PadRight(10 ); 
         dwReturn["GKETITYP"] = " ".PadRight(2 ); 
         dwReturn["GKKOPETI"] = " ".PadRight(2 ); 
         dwReturn["GKVATYP"] = " ".PadRight(2 ); 
         dwReturn["GKKOPVA"] = " ".PadRight(2 ); 
         dwReturn["GKFILLER"] = " ".PadRight(30 ); 
         dwReturn["GKAENDZL"] = " ".PadRight(0 ); 
         dwReturn["GKAENDBEN"] = " ".PadRight(8 ); 
         dwReturn["GKAENDDAT"] = " ".PadRight(0 ); 
         dwReturn["GKNEUBEN"] = " ".PadRight(8 ); 
         dwReturn["GKNEUDAT"] = " ".PadRight(0 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapGSKDZU(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveGSKDZU(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryGSKDZU(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapGSKDZU(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertGSKDZU(dwLocal, ITXDBVERSION);
            }
            UpdateGSKDZU(dwLocal);
        }
        public void InsertGSKDZU(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO GSKDZU(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryGSKDZU(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM GSKDZU WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM GSKDZU  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "GSKDZU";
            Return = Result;
            return Return;
        }
        public void DeleteGSKDZU(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM GSKDZU   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateGSKDZU(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE GSKDZU SET "
                    +"GKMANDANT= :GKMANDANT,"
                    +"GKKUNDNR= :GKKUNDNR,"
                    +"GKART= :GKART,"
                    +"GKVAR= :GKVAR,"
                    +"GKFARBE= :GKFARBE,"
                    +"GKKDGARNB= :GKKDGARNB,"
                    +"GKKDFARBB= :GKKDFARBB,"
                    +"GKAUFMSL= :GKAUFMSL,"
                    +"GKHUELSE= :GKHUELSE,"
                    +"GKSPGEW= :GKSPGEW,"
                    +"GKFDRES= :GKFDRES,"
                    +"GKKF= :GKKF,"
                    +"GKWICKL= :GKWICKL,"
                    +"GKVPEINH= :GKVPEINH,"
                    +"GKBHNR= :GKBHNR,"
                    +"GKNK= :GKNK,"
                    +"GKFARBGR= :GKFARBGR,"
                    +"GKGRPBEZ= :GKGRPBEZ,"
                    +"GKKDFARBN= :GKKDFARBN,"
                    +"GKETITYP= :GKETITYP,"
                    +"GKKOPETI= :GKKOPETI,"
                    +"GKVATYP= :GKVATYP,"
                    +"GKKOPVA= :GKKOPVA,"
                    +"GKFILLER= :GKFILLER,"
                    +"GKAENDZL= :GKAENDZL,"
                    +"GKAENDBEN= :GKAENDBEN,"
                    +"GKAENDDAT= :GKAENDDAT,"
                    +"GKNEUBEN= :GKNEUBEN,"
                    +"GKNEUDAT= :GKNEUDAT,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("GKMANDANT", OracleType.NVarChar).Value = dwData["GKMANDANT"].ToString(); 
          or1.Parameters.Add("GKKUNDNR", OracleType.NVarChar).Value = dwData["GKKUNDNR"].ToString(); 
          or1.Parameters.Add("GKART", OracleType.NVarChar).Value = dwData["GKART"].ToString(); 
          or1.Parameters.Add("GKVAR", OracleType.NVarChar).Value = dwData["GKVAR"].ToString(); 
          or1.Parameters.Add("GKFARBE", OracleType.NVarChar).Value = dwData["GKFARBE"].ToString(); 
          or1.Parameters.Add("GKKDGARNB", OracleType.NVarChar).Value = dwData["GKKDGARNB"].ToString(); 
          or1.Parameters.Add("GKKDFARBB", OracleType.NVarChar).Value = dwData["GKKDFARBB"].ToString(); 
          or1.Parameters.Add("GKAUFMSL", OracleType.NVarChar).Value = dwData["GKAUFMSL"].ToString(); 
          or1.Parameters.Add("GKHUELSE", OracleType.NVarChar).Value = dwData["GKHUELSE"].ToString(); 
          or1.Parameters.Add("GKSPGEW", OracleType.NVarChar).Value = dwData["GKSPGEW"].ToString(); 
          or1.Parameters.Add("GKFDRES", OracleType.NVarChar).Value = dwData["GKFDRES"].ToString(); 
          or1.Parameters.Add("GKKF", OracleType.NVarChar).Value = dwData["GKKF"].ToString(); 
          or1.Parameters.Add("GKWICKL", OracleType.NVarChar).Value = dwData["GKWICKL"].ToString(); 
          or1.Parameters.Add("GKVPEINH", OracleType.NVarChar).Value = dwData["GKVPEINH"].ToString(); 
          or1.Parameters.Add("GKBHNR", OracleType.NVarChar).Value = dwData["GKBHNR"].ToString(); 
          or1.Parameters.Add("GKNK", OracleType.NVarChar).Value = dwData["GKNK"].ToString(); 
          or1.Parameters.Add("GKFARBGR", OracleType.NVarChar).Value = dwData["GKFARBGR"].ToString(); 
          or1.Parameters.Add("GKGRPBEZ", OracleType.NVarChar).Value = dwData["GKGRPBEZ"].ToString(); 
          or1.Parameters.Add("GKKDFARBN", OracleType.NVarChar).Value = dwData["GKKDFARBN"].ToString(); 
          or1.Parameters.Add("GKETITYP", OracleType.NVarChar).Value = dwData["GKETITYP"].ToString(); 
          or1.Parameters.Add("GKKOPETI", OracleType.NVarChar).Value = dwData["GKKOPETI"].ToString(); 
          or1.Parameters.Add("GKVATYP", OracleType.NVarChar).Value = dwData["GKVATYP"].ToString(); 
          or1.Parameters.Add("GKKOPVA", OracleType.NVarChar).Value = dwData["GKKOPVA"].ToString(); 
          or1.Parameters.Add("GKFILLER", OracleType.NVarChar).Value = dwData["GKFILLER"].ToString(); 
          or1.Parameters.Add("GKAENDZL", OracleType.NVarChar).Value = dwData["GKAENDZL"].ToString(); 
          or1.Parameters.Add("GKAENDBEN", OracleType.NVarChar).Value = dwData["GKAENDBEN"].ToString(); 
          or1.Parameters.Add("GKAENDDAT", OracleType.NVarChar).Value = dwData["GKAENDDAT"].ToString(); 
          or1.Parameters.Add("GKNEUBEN", OracleType.NVarChar).Value = dwData["GKNEUBEN"].ToString(); 
          or1.Parameters.Add("GKNEUDAT", OracleType.NVarChar).Value = dwData["GKNEUDAT"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
